<?php
if (isset($_POST['btnSumit'])) {
    $thanhcong = $sp->SanPham_Them($loi);
    if ($thanhcong == true) {
        header("location:?com=sp_list");
    }
}
?>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.ui.all.css"/>
<link rel="stylesheet" type="text/css" href="css/jquery.ui.datepicker.css"/>
<script type="text/javascript" src="js/form.js"></script>
<script type="text/javascript" src="js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="js/jquery-ui.custom.js"></script>
<script type="text/javascript" src="js/jquery.ui.dialog.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#upload_images').ajaxForm({
            beforeSend: function() {

            },
            uploadProgress: function(event, position, total, percentComplete) {

            },
            complete: function(data) {
                var arrRes = JSON.parse(data.responseText);
                alert(arrRes['thongbao']);
                $("#hinhanh").html(arrRes['text'] + arrRes['str_hinhanh']);
                $("#div_upload").dialog('close');
            }
        });
        $("#btnUpload").click(function() {
            $("#div_upload").dialog({
                modal: true,
                title: 'Upload images',
                width: 350,
                draggable: true,
                resizable: false,
                position: "center middle"
            });
        });
        $("#add_images").click(function() {
            $("#wrapper_input_files").append("<input type='file' name='images[]' /><br />");
        });
        $('#idTL').change(function() {
            $.post('ajax/getloai.php', {idTL: $(this).val()}, function(data) {
                $('#idLT').html(data);
            })
        })
    });
</script>
<style>
    #div_upload{font-size:13px;text-align:center}

</style>
<form action="" method="post" name="form_add_dm_ks">
    <div id="admin_navigation">
        <div style="float:left;width:90%">
            <h3>Quản lý sản phẩm: Thêm mới</h3>
        </div>
        <div class="clear"></div>       
        <div style="float:left;width:5%;padding-top:5px">
            <input type="submit" class="save" name="btnSumit" value=""/><br />		
            <span>Save</span>
        </div>
        <div style="float:left;width:5%;padding-top:5px">
            <input type="reset" class="cancel" name="btnCancel" value=""/><br />		
            <span>Reset</span>
        </div>
        <div style="clear:both"></div>
    </div>
    <div style="clear:both"></div>     
    <div id="main_admin">
        <div class="clear"></div>       
        <div id="main_left" style="width:70%">
            <fieldset>
                <legend>Thông tin chung</legend>
                <table>                	
                    <tr>
                        <td style="width: 150px">Chủng loại</td>
                        <td colspan="3">

                            <select name="idTL" id="idTL">
                                <option value="0">-- Chọn --</option>
                                <?php
                                $loaisp = $tl->TheLoai_List();
                                while ($row = mysql_fetch_assoc($loaisp)) {
                                    ?>
                                    <option value="<?php echo $row['idTL']; ?>"><?php echo $row['TenTL']; ?></option>
                                <?php } ?>
                            </select>

                        </td>   
                    </tr>
                    <tr>
                        <td>Loại sản phẩm</td>
                        <td colspan="3">

                            <select name="idLT" id="idLT">
                                <option value="0">-- Chọn --</option>
                                <?php
                                $hang = $lt->LoaiTin_List();
                                while ($row = mysql_fetch_assoc($hang)) {
                                    ?>
                                    <option value="<?php echo $row['idLT']; ?>"><?php echo $row['TenLT']; ?></option>
                                <?php } ?>
                            </select>

                        </td>   
                    </tr>                       
                    <tr>
                        <td>Mã SP</td>
                        <td><input type="text" name="MaSP" id="MaSP" class="tf" value="<?php echo $_POST['MaSP'] ?>" /></td>                        
                    </tr>
                    <tr>
                        <td>Tên SP</td>
                        <td><input type="text" name="TenSP" id="TenSP" class="tf" value="<?php echo $_POST['TenSP'] ?>" /></td>                        
                    </tr> 
                     
                    <tr>
                        <td width="15%">Giá</td>
                        <td><input type="text" name="Gia" id="Gia" class="tf" value="<?php echo $_POST['Gia'] ?>" />
                            <span class="error"><?php echo $loi['Gia']; ?></span>
                        </td>                        
                    </tr>                
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <input type="checkbox" name="AnHien" /> Ẩn &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="checkbox" name="NoiBat" /> Nổi bật &nbsp;&nbsp;&nbsp;&nbsp; 
                            <input type="checkbox" name="trangthai" /> Hết hàng
                        </td>   
                    </tr>   
                    <tr>
                        <td>Hình đại diện</td>
                        <td><input type="text" name="UrlHinh" id="UrlHinh" class="tf" value="<?php echo $_POST['UrlHinh'] ?>"/>
                            <input type="button" name="btnChonFile" value="Chọn hình" onclick="BrowseServer('Images:/', 'UrlHinh')"  />
                            <div id="preview">
                                <div id="thumbnails"></div>
                            </div>   
                            <span class="error"><?php echo $loi['UrlHinh']; ?></span>
                        </td>                        
                    </tr>                                    


                </table>            
            </fieldset>
        </div>	   
        <div id="main_details" style="clear:both;padding-top: 20px">
            <fieldset class="details_form">
                <legend>++ Thông tin chi tiết ++</legend>
                <table>
                    <tr>
                        <td>Chi tiết</td>
                        <td>
                            <div style="width:800px;overflow: hidden">
                                <textarea class="meta" name="MoTa" id="MoTa"><?php echo $_POST['MoTa'] ?></textarea>
                                <script type="text/javascript">
    var editor = CKEDITOR.replace('MoTa', {
        uiColor: '#9AB8F3',
        language: 'vi',
        skin: 'office2003',
        filebrowserImageBrowseUrl: 'ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl: 'ckfinder/ckfinder.html?Type=Flash',
        filebrowserImageUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
        toolbar: [
            ['Source', '-', 'Bold', 'Italic', 'Underline', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'Link', 'Unlink', 'Image', 'Styles', 'Format', 'TextColor', 'BGColor'],
        ]
    });
                                </script>
                            </div>          
                        </td>                        
                    </tr>

                </table>
            </fieldset>

        </div>

        <div class="clr"></div>
    </div>
</form>
<div id="div_upload" style="display:none">
    <form id="upload_images" method="post" enctype="multipart/form-data" enctype="multipart/form-data" action="ajax.php">
        <div style="margin: auto;">       
            <img src="images/add.png" id="add_images" width="32" />
            <div id="wrapper_input_files">
                <input type="file" name="images[]" /><br />
                <input type="file" name="images[]" /><br />
                <input type="file" name="images[]" /><br />
            </div>            
            <div class="clear"></div>       
            <button style="margin-top: 10px;"class="button_colour" type="submit" id="btn_upload_images">                
                <a href="#">Upload</a>
            </button>        
        </div>

    </form>
</div>

